%packages
%\usepackage[dvipdf]{graphicx}
\usepackage[pdftex]{graphicx}
\usepackage[top=2.5cm,left=2.5cm,right=2.5cm,bottom=2.5cm]{geometry}
%\usepackage{a4wide}
\usepackage[utf8x]{inputenc}
\usepackage{float}
\usepackage[german]{babel}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{color}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{url}
\usepackage{parskip}
\usepackage{wrapfig}
\usepackage{ccaption}
\usepackage{listings}
\usepackage{textcomp}
\usepackage{hyperref}
%\usepackage[usenames,dvipsnames]{pstricks}
%\usepackage{pstricks-add}
\usepackage{courier}
\usepackage{caption}
%\usepackage{varioref}
\usepackage[toc,page]{appendix}
\usepackage{hyperref}
\usepackage{breakurl}
\usepackage{bookmark}
\usepackage{tabularx}
\usepackage{subfigure}
\usepackage[xindy,toc]{glossaries}
\usepackage{setspace}
\usepackage{ulem}


\onehalfspacing


%do margins on even pages like in a book
\evensidemargin=-0.7cm
\oddsidemargin=0.7cm

% Makes all pages the height of the text on that page. No extra vertical space is added.
\raggedbottom

%generate glossary
%\makeglossaries

%language selection
\selectlanguage{german}

%color of links
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}



%define caption
\newcommand{\captionfonts}{\footnotesize}
\makeatletter  % Allow the use of @ in command names
\long\def\@makecaption#1#2{%
  \vskip\abovecaptionskip
  \sbox\@tempboxa{{\captionfonts #1: #2}}%
  \ifdim \wd\@tempboxa >\hsize
    {\captionfonts #1: #2\par}
  \else
    \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}
\makeatother   % Cancel the effect of \makeatlettern style


%improve figure placement
\renewcommand{\topfraction}{0.85}
\renewcommand{\textfraction}{0.1}
\renewcommand{\floatpagefraction}{0.75}



%define pagestyle
\pagestyle{fancy}
\fancyheadoffset[LE,RO]{\marginparsep}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} % Lowercase chaptermark
\renewcommand{\sectionmark}[1]{\markright{#1}{}} % Lowercase sectionmark
\fancyhf{}
\fancyhead[LE,RO]{ \footnotesize \thepage}
\fancyhead[RE]{ \footnotesize Kapitel \thechapter: \leftmark}
\fancyhead[LO]{ \footnotesize \rightmark}
%\renewcommand{\footrulewidth}{0.4pt}
\renewcommand{\headrulewidth}{0.4pt}

\fancypagestyle{plain}{
\fancyhead{} % get rid of headers on first pages
\fancyfoot{} % get rid of footers on first pages
\renewcommand{\headrulewidth}{0pt} % and the line
\renewcommand{\footrulewidth}{0pt} % and the line
}
\fancyhfoffset[ER,OR,LO,LR]{0cm}


% butify table of contents
\makeatletter
\renewcommand\tableofcontents{%
  \section*{\contentsname}% or \chapter* but that looks ugly
  \pagestyle{plain}%
  \@starttoc{toc}}
\makeatother 


% No headers on empty pages before new chapter
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}
    \thispagestyle{plain}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother \clearpage{\pagestyle{plain}\cleardoublepage}


%code listing
\lstset{language=Java, 
basicstyle=\ttfamily\fontsize{8}{8}\selectfont, 
showspaces=false, 
showtabs=false, 
tab= , 
keywordstyle=\bfseries, 
showstringspaces=false, 
framexleftmargin=5mm, 
frame=single, 
numbers=left,
numberstyle=\tiny, 
stepnumber=2, 
numbersep=5pt, 
breaklines=true,
xleftmargin=17pt,
captionpos=b,
escapeinside={(*@}{@*)}}


%Javascript language definition
\definecolor{darkgray}{rgb}{.4,.4,.4}

\lstdefinelanguage{JavaScript}{
  keywords={typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break},
  ndkeywords={class, export, boolean, throw, implements, import, this},
  identifierstyle=\color{black},
  sensitive=false,
  commentstyle=\color{darkgray}\ttfamily,
  comment=[l]{//},
  morecomment=[s]{/*}{*/},
}

% Try to avoid single lines at the beginning or end of a page
\widowpenalty=300
\clubpenalty=300



